﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WA.Core;
using WA.Core.DaoInterfaces;
using WA.Core.DomainModel;

namespace WA.Data
{
    public class PartnerDao:BaseDao<Partner,int>,IPartnerDao
    {
        ///WAObjectContext dc = ObjectContextManager.Instance.GetContext();
        ///
        

        public override Partner GetById(int id)
        {
            var result = (from p in db.Partners
                         where p.PartnerID == id
                         select p).First();
            return result;
        }

        #region IPartnerDao Members

        public List<Partner> GetPartnersByName(string name)
        {
            var result = from p in db.Partners
                         where p.Name.Contains(name)
                         select p;

            return result.ToList();

        }

        public bool InsertParnter(Partner partner)
        {
            try
            {
                db.AddPartner(partner);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {                
                //log dao exception
                return false;
            }
        }

        #endregion
    }
}
